import os

def delete_images_without_annotation(directory_path):
    # 遍历目录A下的所有文件
    for file_name in os.listdir(directory_path):
        # 构造图片文件和标注文件的完整路径
        image_path = os.path.join(directory_path, file_name)
        annotation_path = os.path.splitext(image_path)[0] + '.txt'

        # 如果是图片文件且没有对应的标注文件
        if file_name.endswith(('.jpg', '.png', '.jpeg')) and not os.path.exists(annotation_path):
            # 删除图片文件
            os.remove(image_path)
            print(f"已删除无标注文件的图片: {file_name}")

# 替换为你的路径A
directory_path = '/home/champrin/Desktop/record_data/网盘/兑换框数据集/2024-5.15-自家/5.15all'
delete_images_without_annotation(directory_path)
